<?php
$main_path = '/var/www/html/salusbaby/storage/'.$_COOKIE['bid'].'/folders/';
//$main_path = '/home/salusban/www/salusbank.ch/salusme/storage/'.$_COOKIE['bid'].'/folders/';
include '../include/config.php';
if ($_POST['per'] == 'personal') {
    $target_path = '../storage/folders/' . $_POST['mdir'] . '/';
    $_POST['path'] = $target_path;
} else {
    $target_path = $main_path.$_POST['mdir'].'/';
}
$rp = $_POST['rp'];
$mdir = $_POST['mdir'];
$attr = $_POST['attr'];
$date = date('Y-m-d');
$bid = $_POST['bid'];
echo $target_path = $target_path . basename($_FILES['uploadedfile']['name']);

if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

    if ($_POST['per'] == '') {
        $fn = time() . '_' . $bid . substr($_FILES['uploadedfile']['name'], -4);
        rename($target_path, $main_path.$mdir.'/'. $fn);
    } elseif ($_POST['per'] == 'personal') {
        $fn = basename($_FILES['uploadedfile']['name']);
    }
    mysql_query("insert into baby_upload_files (`Sr`,`file_name`,`bid`,`mdir`,`attr`,`date`) values(NULL,'" . $fn . "','" . $_POST['bid'] . "','" . $mdir . "','" . $attr . "','" . $date . "')") or die(mysql_error()); 
    if ($_POST['per'] == 'personal') {
        header('Location:http://'.$_SERVER['HTTP_HOST'].'/salusbaby/user/folder/FolderList');
    } else {
        header('Location:http://'.$_SERVER['HTTP_HOST'].'/salusbaby/user/folder/FolderList');
    }
} else {
    //echo "There was an error uploading the file, please try again!";
    if ($_POST['per'] != '') {
        
    } else {
        header("Location:$rp&s=n");
    }
}
?>
